const express = require('express')
const multer = require('multer');
const art = express.Router()
const fs = require("fs");
const path=require('path')
const img = multer({dest:__dirname +'/img'})
art.use(img.any()) 
const {getArt,postArt,postAddArt,getArtID,postUpdateArt,postDeleteArt} = require('../../service/art/artService') 

//获取艺术涂料数据
art.get('/',getArt)
art.post('/',postArt)

//id查询
art.get('/id',getArtID)

//添加艺术涂料数据
art.post('/add',postAddArt)

//修改艺术涂料数据
art.post('/update',postUpdateArt)

//删除艺术涂料数据
art.post('/delete',postDeleteArt)
//添加图片
art.post('/img',async(req,res,next) =>{
  const files = req.files
  let oldfile = req.files[0].path
  let newfile = req.files[0].path +path.parse(req.files[0].originalname).ext
  fs.renameSync(oldfile,newfile)
  res.send({
    err:0,
    msg:'上传文件成功',
    
    // url:"http://127.0.0.1:3000/imgArt/"+req.files[0].filename+path.parse(req.files[0].originalname).ext
    url:"http://47.119.123.95:3000/imgArt/"+req.files[0].filename+path.parse(req.files[0].originalname).ext

  })
})


module.exports = art